@echo off

@if "%1"=="" (
   @echo usage: %~n0 certificate's subject name
   @goto :hashend
)

set CERTHASH=

for /f "tokens=2,* usebackq" %%a in ( `certutil -store my %1 ^| findstr /c:"Cert Hash(sha1)"` ) do (
    set CERTHASH=%%b
)

@if NOT "%CERTHASH%" == "" (
 set CERTHASH=%CERTHASH: =%
)

set %1CERTHASH=%CERTHASH%

:hashend
